package com.battery.system.service.battery.impl;

import com.battery.common.core.text.Convert;
import com.battery.system.domain.PurchaseStatus;
import com.battery.system.mapper.PurchaseStatusMapper;
import com.battery.system.service.battery.IPurchaseStatusService;
import com.battery.system.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * 采购订单状态Service业务层处理
 *
 * @author battery
 * @date 2021-01-22
 */
@Service
public class PurchaseStatusServiceImpl extends BaseServiceImpl<PurchaseStatus> implements IPurchaseStatusService {
    @Autowired
    private PurchaseStatusMapper purchaseStatusMapper;

    /**
     * 查询采购订单状态
     *
     * @param purchaseId 采购订单状态ID
     * @return 采购订单状态
     */
    @Override
    public PurchaseStatus selectPurchaseStatusById(String purchaseId) {
        return purchaseStatusMapper.selectPurchaseStatusById(purchaseId);
    }

    /**
     * 查询采购订单状态列表
     *
     * @param purchaseStatus 采购订单状态
     * @return 采购订单状态
     */
    @Override
    public List<PurchaseStatus> selectPurchaseStatusList(PurchaseStatus purchaseStatus) {
        return purchaseStatusMapper.selectPurchaseStatusList(purchaseStatus);
    }

    /**
     * 新增采购订单状态
     *
     * @param purchaseStatus 采购订单状态
     * @return 结果
     */
    @Override
    public int insertPurchaseStatus(PurchaseStatus purchaseStatus) {
        return purchaseStatusMapper.insertPurchaseStatus(purchaseStatus);
    }

    /**
     * 修改采购订单状态
     *
     * @param purchaseStatus 采购订单状态
     * @return 结果
     */
    @Override
    public int updatePurchaseStatus(PurchaseStatus purchaseStatus) {
        return purchaseStatusMapper.updatePurchaseStatus(purchaseStatus);
    }

    /**
     * 删除采购订单状态对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deletePurchaseStatusByIds(String ids) {
        return purchaseStatusMapper.deletePurchaseStatusByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除采购订单状态信息
     *
     * @param purchaseId 采购订单状态ID
     * @return 结果
     */
    @Override
    public int deletePurchaseStatusById(String purchaseId) {
        return purchaseStatusMapper.deletePurchaseStatusById(purchaseId);
    }

    @Override
    public void updatePurchaseByOutOrder(PurchaseStatus purchaseStatus) {
        purchaseStatusMapper.updatePurchaseByOutOrder(purchaseStatus);
    }


    @Override
    public PurchaseStatus selectByOOutOrder(String tradeNo) {
        Example example = new Example(PurchaseStatus.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("out_order", tradeNo);
        return purchaseStatusMapper.selectOneByExample(example);
    }
}
